Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix squiggle-lang workers in hub #3456

Merged
merged 2 commits into from
Dec 5, 2024
Merged

Fix squiggle-lang workers in hub #3456

merged 2 commits into from
Dec 5, 2024

Conversation

berekuk
Copy link
Collaborator

@berekuk berekuk commented Dec 5, 2024

The annoying downside of this PR is that it will spam the server logs with errors in dev mode:

error TP1001 new Worker(./esbuild-worker.js relative, {"type": "module"}) is not statically analyse-able
   6 |         }
   7 |         super();
>  8 |         this.worker = new Worker(new URL("./esbuild-worker.js", import.meta.url), {
     |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>  9 |             type: "module",
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 10 |         });
     | ^^^^^^^^^^^
  11 |     }

These errors are caused by turbopack, which is unable to analyze two-arg version of new Worker. (source here, but I can't say I understand how exactly pattern-matching is implemented, and it's not documented anywhere).

The closest issue I could find in Next.js is this: vercel/next.js#72397; note that vercel/next.js#72397 (comment) specifically mentions the { type: "module" }, which causes errors.

The version without { type: "module" } would work if I compile the worker to esbuild-worker.cjs, and that's how I tried to do it previously, but .cjs files don't work on Vercel (they're served with the wrong content-type).

If there's no .cjs extension, and no { type: "module" }, then turbopack, and I think webpack too, would still interpret the worker URL to be a module (probably because squiggle-lang is an ESM package, configured with "type": "module" in package.json), and inject "import" statements in dev, which then breaks the worker when the browser tries to run it, because the worker constructor didn't ask for it be to be a module.

There might be some combination of esbuild parameters that would solve it, but I couldn't find it.

To reiterate, these errors don't prevent next dev --turbo from functioning. The only issue that I can find is console errors, and I hope that those will be fixed on turbopack side eventually.

Copy link

vercel bot commented Dec 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
quri-hub ✅ Ready (Inspect) Visit Preview Dec 5, 2024 6:18pm
squiggle-components ✅ Ready (Inspect) Visit Preview Dec 5, 2024 6:18pm
squiggle-website ✅ Ready (Inspect) Visit Preview Dec 5, 2024 6:18pm
1 Skipped Deployment
Name Status Preview Updated (UTC)
quri-ui ⬜️ Ignored (Inspect) Visit Preview Dec 5, 2024 6:18pm

Copy link

changeset-bot bot commented Dec 5, 2024

⚠️ No Changeset found

Latest commit: f4f7abb

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@OAGr
Copy link
Contributor

OAGr commented Dec 5, 2024

Great, this seems to fix that main issue!

@OAGr
Copy link
Contributor

OAGr commented Dec 5, 2024

This closed #3455

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants